#!/usr/bin/evn python
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： singleton_util
Description :
Author : 'Mark.Wei'
date： 2022/6/1
-------------------------------------------------
Change Activity:
2022/6/1:
-------------------------------------------------
"""

import threading


def singleton(cls):
    _instance = {}

    def _singleton(*args, **k_args):
        if cls not in _instance:
            _instance[cls] = cls(*args, **k_args)
        return _instance[cls]

    return _singleton


class SingletonType(type):
    _instance_lock = threading.Lock()

    def __call__(cls, *args, **kwargs):
        if not hasattr(cls, "_instance"):
            with SingletonType._instance_lock:
                if not hasattr(cls, "_instance"):
                    cls._instance = super(SingletonType, cls).__call__(*args, **kwargs)
        return cls._instance
